Real World Windows 10 Development by Edward Moemeka & Elizabeth Moemeka

Real World Windows 10 Development by Edward Moemeka & Elizabeth Moemeka

Author:Edward Moemeka & Elizabeth Moemeka
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


In Listing 7-41, ToggleRecordVideo uses the familiar MediaCapture class to enable the video capture functionality. The only real difference between the code here and the code used in the audio capture samples is that the encoding profile is mapped to a video file format (in this case mp4). This choice is also reflected in the file extension used.

Background Audio

The previous section started delving into the intricacies of MediaElement. You saw how it can be used to play audio data located on the user’s machine or from a remote server. When these audio files play, however, they are designed by default to only play in the foreground. In the world of Windows 10, this means once you switch away from your app (minimize on the desktop), the sound stops. You can try this now with the app at this point. Start it and the Big Buck Bunny begins to play, minimize it (or navigate away from it on your Windows 10 mobile device/emulator) and the sound stops. Navigate back to the application, and the audio starts again. If you paid close attention to the playback time of the media when you navigated away, notice that it has increased in value from the point at which you navigated away (and also notice that the media is playing from a later position). This is because the audio has been playing while the app was shifted to the background. However, because audio configured in this manner can’t be heard when the app hosting it is no longer visible to the user, you hear nothing when you switch to a different app.

Enabling background playback requires three steps. First, you need to declaratively tell Windows that the MediaElement is designed for background audio playback. You then need to inform Windows of your intent to have the application running in the background (for the purpose of playing the audio). Finally, you need to hook your application up to the background audio playback infrastructure so that a user can use the Windows media playback controls to control the background audio. Let’s get started. Let’s implement background media playback for the video playing when the app starts (your “most recent event” video).

In the MediaElement tag, you assign a value to the AudioCategory property. The system uses this property to identify and manage the performance and integration of audio. When the value is set to BackgroundCapableMedia, it earmarks audio being played through the MediaElement as available to the background audio player.

The next step is to add a new declaration in the Declarations tab of the project’s package.appxmanifest configuration file. A background task must be implemented within a Windows Runtime Component, a kind of class library that can be interacted with from within any of the supported UWP languages. Right-click the Solution Explorer and add a new project to the solution entitled BMX.BackgroundTasks. Once created, remove the default class that is added (class1.cs) and add a new class called AudioPlayback. (Note that we will delve into background tasks in more detail in Chapter 9.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.